using Microsoft.WindowsAzure.StorageClient;

namespace AzureContrib.WindowsAzure.StorageClient
{
	/// <summary>
	/// Extensions to <see cref="IQueue{T}"/>
	/// </summary>
	public static class QueueExtensions
	{
		/// <summary>
		/// <see cref="CloudQueue.AddMessage(Microsoft.WindowsAzure.StorageClient.CloudQueueMessage)"/> but we add a <see cref="CloudQueueMessage{T}"/> with a nice paylod <typeparamref name="T"/>.
		/// </summary>
		/// <param name="queue">The queue to enqeue to.</param>
		/// <param name="payload">The message to enqueue as a <see cref="CloudQueueMessage{T}"/></param>
		public static void Enqueue<T>(this IQueue<T> queue, T payload)
		{
			var cloudQueueMessage = payload.AsMessage();
			var queueMessage = new CloudQueueMessage<T>(cloudQueueMessage);
			queue.Enqueue(queueMessage);
		}
	}
}